package thinking.in.spring.boot.config;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.web.context.WebServerInitializedEvent;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.event.EventListener;
import org.springframework.web.reactive.function.server.RouterFunction;
import org.springframework.web.reactive.function.server.ServerResponse;
import reactor.core.publisher.Mono;

import static org.springframework.web.reactive.function.server.RequestPredicates.GET;
import static org.springframework.web.reactive.function.server.RouterFunctions.route;
import static org.springframework.web.reactive.function.server.ServerResponse.ok;

/**
 * @author : wenchao.long
 * @date : Created in 2024-12-09 下午 10:04 周一
 * @description :
 */
@Configuration
//@SpringBootApplication
//@EnableAutoConfiguration
public class WebConfiguration {

	@Bean
	public RouterFunction<ServerResponse> helloWorld() {
		return route(GET("/hello-world"),
				request -> ok().body(Mono.just("Hello, World"), String.class));
	}

	@EventListener(WebServerInitializedEvent.class)
	public void onWebServerReady(WebServerInitializedEvent event) {
		System.out.println("当前WebServer实现类为: " + event.getWebServer().getClass().getName());
	}

	@Bean
	public ApplicationRunner runner(BeanFactory beanFactory) {
		return args -> {
			System.out.println("当前helloWorld Bean 实现类为:" + beanFactory.getBean("helloWorld").getClass().getName());
			System.out.println("当前WebConfiguration 实现类为:" + beanFactory.getBean(WebConfiguration.class).getClass().getName());
		};
	}
}
